package com.ybxx.hr.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;

import com.ybxx.core.command.QueryFilter;
import com.ybxx.core.util.UUIDGenerator;
import com.ybxx.core.web.action.BaseAction;
import com.ybxx.hr.model.Work;
import com.ybxx.hr.service.WorkService;

public class WorkAction extends BaseAction {
	@Resource
	private WorkService workService;
	private Work work;
	private List<Work> works;
	private String msg="succ";
	/*删除*/
	public String remove(){
		try{
			workService.remove(work.getWid());
		}catch(Exception ex){
			msg="工种删除失败";
		}finally{
			return "succ";
		}
	}
	/*加载查看时候需要展示的数据*/
	public String view(){
		if(work!=null && StringUtils.isNotEmpty(work.getWid())){
			work=workService.get(work.getWid());
		}
		return "view";
	}
	public String queryPage(){
		QueryFilter filter=new QueryFilter(getRequest());
		works=workService.queryPage(work,filter);
		super.setRownum(filter.getPagingBean().getTotalItems());
		super.setCurrentpage(Integer.parseInt(filter.getPagingBean().getStart()+"")/Integer.parseInt(filter.getPagingBean().getPageSize()+"")+1);
		super.setPageSize(Integer.parseInt(filter.getPagingBean().getPageSize()+""));
		return "queryPage";
	}
	/*保存新增，修改信息*/
	public String save(){
		if(StringUtils.isEmpty(work.getWid())){
			work.setWid(UUIDGenerator.getUUID());
		}
		try{
			workService.save(work);
		}catch(Exception ex){
			msg="工种信息保存失败.";
		}finally{
			return "succ";
		}
	}
	/*加载修改时候需要展示的数据*/
	public String load(){
		if(work!=null && StringUtils.isNotEmpty(work.getWid())){
			work=workService.get(work.getWid());
		}
		return "load";
	}
	public Work getWork() {
		return work;
	}
	public void setWork(Work work) {
		this.work = work;
	}
	public List<Work> getWorks() {
		return works;
	}
	public void setWorks(List<Work> works) {
		this.works = works;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
}
